﻿using System;
using System.Collections.Generic;
using System.Text;

namespace Evaluant.NLinq.Expressions
{
    public class OrderByClause : QueryBodyClause, IList<OrderByCriteria>
    {
        public OrderByClause(params OrderByCriteria[] criterias)
        {
            this.criterias = new List<OrderByCriteria>(criterias);
        }

        public OrderByClause(IEnumerable<OrderByCriteria> criterias)
        {
            this.criterias = new List<OrderByCriteria>(criterias);
        }

        private IList<OrderByCriteria> criterias;

        public IList<OrderByCriteria> Criterias
        {
            get { return criterias; }
            set { criterias = value; }
        }

        public override void Accept(NLinqVisitor visitor)
        {
            visitor.Visit(this);
        }



        public override ClauseTypes ClauseType
        {
            get { return ClauseTypes.OrderBy; }
        }


        #region IList<OrderByCriteria> Members

        public int IndexOf(OrderByCriteria item)
        {
            return criterias.IndexOf(item);
        }

        public void Insert(int index, OrderByCriteria item)
        {
            criterias.Insert(index, item);
        }

        public void RemoveAt(int index)
        {
            criterias.RemoveAt(index);
        }

        public OrderByCriteria this[int index]
        {
            get
            {
                return criterias[index];
            }
            set
            {
                criterias[index] = value;
            }
        }

        #endregion

        #region ICollection<OrderByCriteria> Members

        public void Add(OrderByCriteria item)
        {
            this.criterias.Add(item);
        }

        public void Clear()
        {
            criterias.Clear();
        }

        public bool Contains(OrderByCriteria item)
        {
            return criterias.Contains(item);
        }

        public void CopyTo(OrderByCriteria[] array, int arrayIndex)
        {
            criterias.CopyTo(array, arrayIndex);
        }

        public int Count
        {
            get { return criterias.Count; }
        }

        public bool IsReadOnly
        {
            get { return criterias.IsReadOnly; }
        }

        public bool Remove(OrderByCriteria item)
        {
            return criterias.Remove(item);
        }

        #endregion

        #region IEnumerable<OrderByCriteria> Members

        public IEnumerator<OrderByCriteria> GetEnumerator()
        {
            return criterias.GetEnumerator();
        }

        #endregion

        #region IEnumerable Members

        System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
        {
            return criterias.GetEnumerator();
        }

        #endregion

    }
}
